//
//  PeopleFunyListViewController.m
//  markmap
//
//  Created by 甘世清 on 2024/5/15.
//

#import "PeopleFunyListViewController.h"
#import "FunyModel.h"
#import "FunPicTableViewCell.h"
@interface PeopleFunyListViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation PeopleFunyListViewController

- (void)SQ_viewWillAppear:(BOOL)animated{
    [self SQ_Header];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"动态");
}
- (void)SQ_UIViewForSelfView{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(TopHeight, 0, 0, 0));
    }];
    [self SQ_tableViewAddRefresh];
}
 
- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"1" forKey:@"current"];
    [dic setObject:@"20" forKey:@"size"];
    [dic setObject:self.uid forKey:@"uid"];
    [HttpTool post:Url46 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        self.page = 1;
        [self.tableView.mj_header endRefreshing];
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSArray * array = [FunyModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
        [self.jsonArray removeAllObjects];
        [self.jsonArray addObjectsFromArray:array];
        [self.tableView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [self.tableView.mj_header endRefreshing];
    }];
}
- (void)SQ_Foother{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[NSString stringWithFormat:@"%d",self.page+1] forKey:@"current"];
    [dic setObject:@"20" forKey:@"size"];
    [dic setObject:self.uid forKey:@"uid"];
    [HttpTool post:Url46 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        self.page ++;
        NSDictionary * data = [[NSDictionary alloc]initWithDictionary:httpModel.data];
        NSArray * array = [FunyModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"records"]];
        [self.jsonArray addObjectsFromArray:array];
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [self.tableView.mj_footer endRefreshing];
    }];
}
 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     return self.jsonArray.count;
}
 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FunPicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FunPicTableViewCell"];
    if (!cell) {
        cell = [[FunPicTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"FunPicTableViewCell"];
    }
    FunyModel * model =  [self.jsonArray objectAtIndex:indexPath.item];
    model.name = self.name;
    model.portrait = self.portrait;
    cell.model =  model;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [FunPicTableViewCell FSCellHeightForTableView:tableView indexPath:indexPath cellContentViewWidth:0 bottomOffset:10];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    FunyPicDetailsViewController * vc = [[FunyPicDetailsViewController alloc]init];
    vc.model = [self.jsonArray objectAtIndex:indexPath.item];
    [self SQ_pushViewControllerFull:vc];
}


@end
